import { Cache } from "../../../cache/Cache";
import { ItemData } from "../../../resource/info/ItemData";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { ECareerSecondTran } from "../../../../../Message/Public/ECareerSecondTran";
import { SecondCareerConfig } from "../../../resource/SecondCareerConfig";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
import { CareerUtil } from "../../common/util/CareerUtil";
import { JSON } from "../../../../../com/mui/serialization/json/JSON";
import { SFightAttribute } from "../../../../../Message/Public/SFightAttribute";
import { EJewel } from "../../../../../Message/Public/EJewel";
import { EEntityAttribute } from "../../../../../Message/Public/EEntityAttribute";
type int = number;
//class SecondCareerUtil
    
    export  class SecondCareerUtil
    {
        

        public static isEnabledBaseCareer(): Boolean
        {
            return Cache.instance.role.careerEnabled == Cache.instance.role.careerBasic;
        }

        public static getSecondCareerItemData(arg1: int, arg2: int, arg3: ItemData): ItemData
        {
            var loc1=0;
            var loc3=null;
            var loc4=null;
            var loc5=arg3.category;
            switch (loc5) 
            {
                case ECategory._ECategoryEquip: case ECategory._ECategoryMount:
                {
                    loc1 = ECareerSecondTran._ECareerSecondEquip;
                    break;
                }
                case ECategory._ECategoryRune:
                {
                    loc1 = ECareerSecondTran._ECareerSecondRune;
                    break;
                }
                case ECategory._ECategoryMount:
                {
                    loc1 = ECareerSecondTran._ECareerSecondJewel;
                    break;
                }
            }
            var loc2;
            if ((loc2 = SecondCareerConfig.instance.getSecondCode(loc1, arg3.itemCode, arg1, arg2)) != 0) 
            {
                (loc3 = new SPlayerItem()).itemCode = loc2;
                loc3.itemAmount = arg3.itemAmount;
                loc3.playerId = arg3.playerId;
                loc3.posType = arg3.posType;
                loc3.uid = arg3.uid;
                loc3.jsStr = arg3.data.jsStr == "" || arg3.data.jsStr == null ? "" : SecondCareerUtil.changeExJsStr(arg3.data.jsStr, arg1, arg2);
                loc4 = new ItemData(loc3);
                if (CareerUtil.isCareerSuit(loc4.itemInfo.item.career, arg2)) 
                {
                    return loc4;
                }
                return null;
            }
            return null;
        }

        public static getSecondCareerWeaponsDic(arg1: int, arg2: int, arg3: Map<any, any> /* flash.utils.Dictionary */): Map<any, any> /* flash.utils.Dictionary */
        {
            var loc2=null;
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            var loc3=0;
            var loc4=arg3;
            for (loc2 in loc4) 
            {
                loc1[loc2] = SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondEquip, arg3[loc2], arg1, arg2);
            }
            return loc1;
        }

        public static changeExJsStr(arg1: string, arg2: int, arg3: int): string
        {
            var loc4=null;
            var loc5=0;
            var loc6=null;
            var loc7=null;
            var loc1=JSON.deserialize(arg1);
            var loc2=CareerUtil.isPhysicalCareer(arg2);
            var loc3=CareerUtil.isPhysicalCareer(arg3);
            loc5 = 1;
            while (loc5 <= 6) 
            {
                loc6 = "hole" + loc5;
                if (loc1.hasOwnProperty(loc6) && loc1[loc6] > 1) 
                {
                    loc1[loc6] = SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondJewel, loc1[loc6], arg2, arg3);
                }
                ++loc5;
            }
            loc5 = 1;
            while (loc5 <= 6) 
            {
                loc6 = "addition" + loc5;
                if (loc1.hasOwnProperty(loc6) && loc1[loc6] > 0) 
                {
                    loc1[loc6] = SecondCareerUtil.getSecondAddition(loc1[loc6], arg2, arg3);
                }
                ++loc5;
            }
            if (loc1.hasOwnProperty("rune_swallow") && loc1["rune_swallow"] is Array) 
            {
                loc4 = [];
                loc7 = loc1["rune_swallow"] as Array<any>;
                loc5 = 0;
                while (loc5 < loc7.length) 
                {
                    loc4.push(SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondRune, loc7[loc5], arg2, arg3));
                    ++loc5;
                }
                loc1["rune_swallow"] = loc4;
            }
            if (loc1.hasOwnProperty("bWeaponFashionModel")) 
            {
                loc1["bWeaponFashionModel"] = SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondEquip, loc1["bWeaponFashionModel"], arg2, arg3);
            }
            if (loc1.hasOwnProperty("weaponfashionModel")) 
            {
                loc1["weaponfashionModel"] = SecondCareerConfig.instance.getSecondCode(ECareerSecondTran._ECareerSecondEquip, loc1["weaponfashionModel"], arg2, arg3);
            }
            if (loc2 != loc3) 
            {
                SecondCareerUtil.switchValue("b_power", "b_spirit", loc1);
                SecondCareerUtil.switchValue("b_agile", "b_brains", loc1);
                SecondCareerUtil.switchValue("m_power_g", "m_spirit_g", loc1);
                SecondCareerUtil.switchValue("m_agile_g", "m_brains_g", loc1);
            }
            return JSON.serialize(loc1);
        }

        public static getSecondAttrsByAdictions(arg1: SFightAttribute, arg2: Array<any>, arg3: int, arg4: int): Array<any>
        {
            var loc3=0;
            var loc1=[];
            var loc2=0;
            while (loc2 < arg2.length) 
            {
                loc3 = SecondCareerUtil.getSecondAddition(int(arg2[loc2]), arg3, arg4);
                loc1.push(SecondCareerUtil.getPlayerAttrByAddition(arg1, loc3));
                ++loc2;
            }
            return loc1;
        }

        public static getSecondAddition(arg1: int, arg2: int, arg3: int): int
        {
            var loc1=CareerUtil.isPhysicalCareer(arg2);
            var loc2=CareerUtil.isPhysicalCareer(arg3);
            if (loc1 != loc2) 
            {
                var loc3=arg1;
                switch (loc3) 
                {
                    case EJewel._EJewelPower:
                    {
                        return EJewel._EJewelSpiritual;
                    }
                    case EJewel._EJewelAgile:
                    {
                        return EJewel._EJewelBrains;
                    }
                    case EJewel._EJewelBrains:
                    {
                        return EJewel._EJewelAgile;
                    }
                    case EJewel._EJewelSpiritual:
                    {
                        return EJewel._EJewelPower;
                    }
                    case EJewel._EJewelPhysicalAttack:
                    {
                        return EJewel._EJewelMagicAttack;
                    }
                    case EJewel._EJewelMagicAttack:
                    {
                        return EJewel._EJewelPhysicalAttack;
                    }
                    case EJewel._EJewelPhysicalCrit:
                    {
                        return EJewel._EJewelMagicCrit;
                    }
                    case EJewel._EJewelMagicCrit:
                    {
                        return EJewel._EJewelPhysicalCrit;
                    }
                }
            }
            return arg1;
        }

        public static getSecondAttribute(arg1: int, arg2: int, arg3: int): int
        {
            var loc1=CareerUtil.isPhysicalCareer(arg2);
            var loc2=CareerUtil.isPhysicalCareer(arg3);
            if (loc1 != loc2) 
            {
                var loc3=arg1;
                switch (loc3) 
                {
                    case EEntityAttribute._EAttributePower:
                    {
                        return EEntityAttribute._EAttributeSpiritual;
                    }
                    case EEntityAttribute._EAttributeAgile:
                    {
                        return EEntityAttribute._EAttributeBrains;
                    }
                    case EEntityAttribute._EAttributeBrains:
                    {
                        return EEntityAttribute._EAttributeAgile;
                    }
                    case EEntityAttribute._EAttributeSpiritual:
                    {
                        return EEntityAttribute._EAttributePower;
                    }
                    case EEntityAttribute._EAttributePhysicalAttack:
                    {
                        return EEntityAttribute._EAttributeMagicAttack;
                    }
                    case EEntityAttribute._EAttributeMagicAttack:
                    {
                        return EEntityAttribute._EAttributePhysicalAttack;
                    }
                    case EEntityAttribute._EAttributePhysicalCrit:
                    {
                        return EEntityAttribute._EAttributeMagicCrit;
                    }
                    case EEntityAttribute._EAttributeMagicCrit:
                    {
                        return EEntityAttribute._EAttributePhysicalCrit;
                    }
                }
            }
            return arg1;
        }

        public static getPlayerAttrByAddition(arg1: SFightAttribute, arg2: int): int
        {
            var loc1=arg2;
            switch (loc1) 
            {
                case EJewel._EJewelAgile:
                {
                    return arg1.agile;
                }
                case EJewel._EJewelBlock:
                {
                    return arg1.block;
                }
                case EJewel._EJewelBlockRate:
                {
                    return arg1.blockPercentage;
                }
                case EJewel._EJewelBrains:
                {
                    return arg1.brains;
                }
                case EJewel._EJewelHabitus:
                {
                    return arg1.habitus;
                }
                case EJewel._EJewelHit:
                {
                    return arg1.hit;
                }
                case EJewel._EJewelHitRate:
                {
                    return arg1.hitPercentage;
                }
                case EJewel._EJewelJouk:
                {
                    return arg1.jouk;
                }
                case EJewel._EJewelJoukRate:
                {
                    return arg1.joukPercentage;
                }
                case EJewel._EJewelLife:
                {
                    return arg1.maxLife;
                }
                case EJewel._EJewelMagicAttack:
                {
                    return arg1.magicAttack;
                }
                case EJewel._EJewelMagicCrit:
                {
                    return arg1.magicCrit;
                }
                case EJewel._EJewelMagicDefense:
                {
                    return arg1.magicDefense;
                }
                case EJewel._EJewelMagicReliefRate:
                {
                    return arg1.reliefPercentage;
                }
                case EJewel._EJewelMana:
                {
                    return arg1.maxMana;
                }
                case EJewel._EJewelPass:
                {
                    return arg1.pass;
                }
                case EJewel._EJewelPassRate:
                {
                    return arg1.passPercentage;
                }
                case EJewel._EJewelPhysicalAttack:
                {
                    return arg1.physicalAttack;
                }
                case EJewel._EJewelPhysicalCrit:
                {
                    return arg1.physicalCrit;
                }
                case EJewel._EJewelPhysicalDefense:
                {
                    return arg1.physicalDefense;
                }
                case EJewel._EJewelPhysicalReliefRate:
                {
                    return arg1.reliefPercentage;
                }
                case EJewel._EJewelPower:
                {
                    return arg1.power;
                }
                case EJewel._EJewelRelief:
                {
                    return arg1.relief;
                }
                case EJewel._EJewelReliefRate:
                {
                    return arg1.reliefPercentage;
                }
                case EJewel._EJewelSpeededUp:
                {
                    return arg1.speededUp;
                }
                case EJewel._EJewelSpeededUpRate:
                {
                    return arg1.speededUpPercentage;
                }
                case EJewel._EJewelSpiritual:
                {
                    return arg1.spiritual;
                }
                case EJewel._EJewelToughness:
                {
                    return arg1.toughness;
                }
                case EJewel._EJewelToughnessRate:
                {
                    return arg1.toughnessPercentage;
                }
            }
            return 0;
        }

        /* internal  */static switchValue(arg1: string, arg2: string, arg3: Object): void
        {
            var loc1=undefined;
            if (arg3.hasOwnProperty(arg1) && arg3.hasOwnProperty(arg2)) 
            {
                loc1 = arg3[arg1];
                arg3[arg1] = arg3[arg2];
                arg3[arg2] = loc1;
            }
            return;
        }
    }
